package com.zzh.leetcode;
/*
 * @Auther : wenrouyue
 * @Date : 2022/2/28-9:50
 */
//输入：nums = [2,7,11,15], target = 9
//输出：[0,1]
//解释：因为 nums[0] + nums[1] == 9 ，返回 [0, 1] 。

import java.lang.reflect.Array;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;

public class SumByTwoNum {
    public static void timeUtils() throws ParseException {
        String t1 = "2022-02-28 14:12:34";
        String t2 = "2022-03-28 11:11:33";
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" );
        Date dt1 = simpleDateFormat.parse(t1);
        Date dt2 = simpleDateFormat.parse(t2);
        long diff = dt2.getTime() - dt1.getTime();
        long days = diff / (1000 * 24 * 60 * 60);
        long hours = (diff-days*(1000 * 60 * 60 * 24))/(1000* 60 * 60);
        long minutes = (diff-days*(1000 * 60 * 60 * 24)-hours*(1000* 60 * 60))/(1000* 60);
        System.out.println(""+days+"天"+hours+"小时"+minutes+"分");
    }
    public static int[] twoSum(int[] nums, int target){
        int len = nums.length;
        HashMap<Integer, Integer> map = new HashMap<>(len - 1);
        map.put(nums[0],0);
        for (int i = 1; i < len; i++) {
            if (map.containsKey(target - nums[i])){
                return new int[]{map.get(target - nums[i]),i};
            }
            map.put(nums[i],i);
        }
        return null;
    }
    public static void main(String[] args) {
        int[] nums= new int[]{5,7,11,15};
        System.out.println(Arrays.toString(twoSum(nums, 18)));
    }
}
